package design2.abstract_factory.example;

import design2.abstract_factory.example.app.Application;
import design2.abstract_factory.example.factories.GUIFactory;
import design2.abstract_factory.example.factories.MacOSFactory;
import design2.abstract_factory.example.factories.WindowsFactory;

public class Demo {

	public static void main(String[] args) {
		Application application=configureApplication();
		application.paint();
	}

	/**
	 * 应用程序选择工厂类型并在运行时创建它（通常在初始化阶段），具体取决于配置或环境变量。
	 * @return
	 */
	private static Application configureApplication(){
		GUIFactory guiFactory;
		String osName=System.getProperty("os.name").toLowerCase();
		if(osName.contains("mac")){
			guiFactory=new MacOSFactory();

		}else{
			guiFactory=new WindowsFactory();
		}
		return new Application(guiFactory);
	}
}
